package com.nuoniu.sibanyun.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.entity.SysEmployee;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.dto.SysUserDto;
import com.nuoniu.sibanyun.entity.vo.OfficeTreeData;
import com.nuoniu.sibanyun.entity.vo.SysEmployeeSimpleVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

//*
// * <p>
// * 员工表 Mapper 接口
// * </p>
// *
// * @author baiqiang
// * @since 2020-05-29
//

@Mapper
@Component
public interface SysEmployeeMapper extends BaseMapper<SysEmployee> {

//*
//     * 根据机构获取员工
//     * @author 小啊刚
//     * @date 2020/5/30
//

    @Select("select concat(e.employee_id, '_user') as id, e.employee_name as name, #{id} as parentId from hr_employee e left join sys_user u on u.id = e.employee_id where e.office_id = #{id} and u.status = 0")
    List<OfficeTreeData> getByOffice(Long id);

//*
//     * 根据用户id获取员工
//     * @author 小啊刚
//     * @date 2020/6/3
//

    @Select("select * from hr_employee where employee_id = #{id}")
    SysEmployee getByUser(Long id);

//*
//     * 修改员工姓名
//     * @author 小啊刚
//     * @date 2020-08-05
//

    @Update("update hr_employee set employee_name = #{realName} where employee_id = #{id}")
    void updateEmpName(Long id, String realName);


    Page<SysEmployeeSimpleVo> pageSysEmployeeSimpleVo(Page page,Integer companyId, Integer officeId,String searchKey);

    @Select("select phone_number from hr_employee where tenant_id=#{companyId} and employee_id is null")
    String[] getPhoneByCompanyId(Integer companyId);

//*
//     * 根据手机号查找员工
//     * @author 小啊刚
//     * @date 2021-07-28
//

    @Select("select * from hr_employee where phone_number=#{userPhone}")
    SysEmployee getByUserPhone(String userPhone);

//*
//     * 删除用户
//     * @author 小啊刚
//     * @date 2022-06-02
//

    @Delete("delete from hr_employee where employee_id=#{userId}")
    void deleteByUserId(Integer userId);


    Page<SysEmployee> getUserPage(Page page, @Param("dto") SysUserDto userDto);

}
